﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CivLib.CivSpatial;

namespace CivLib.CivNum
{
  class Interp
  {
    /// <summary>
    /// Method to interpolate for a 2D point
    /// </summary>
    /// <param name="first">First point</param>
    /// <param name="second">Second point</param>
    /// <param name="abscissa">desired coordinate(x value)</param>
    /// <returns>Interpolated 2D point</returns>
    public static CivPoint2D Linear(CivPoint2D first, CivPoint2D second, 
      double abscissa)
    {
      CivPoint2D interpolated;
      interpolated.x = abscissa;
      double deltax = second.x - first.x;
      double deltay = second.y - first.y;
      interpolated.y = first.y + (deltay / deltax) * (abscissa - first.x);

      return interpolated;
    }
  }
}
